<?php
/**
 * Created by PhpStorm.
 * User: changyifan
 * Date: 2018/1/4
 * Time: 上午10:51
 * 教学内容管理
 */

namespace Home\Controller;
use Think\Controller;

class MethodController extends MainController{
    /* <-------------     教学视频管理   -------------> */
    public function  method_video_manage(){

        $this->assign('teachermethod_info',$this->event->getTeacherMethodList());
        $this->assign('chapter_info',$this->event->getChapterList());
        $this->assign('section_info',$this->event->getSectionList());
        $this->display();
    }
    public function medthod_video_manage_ShowDatatables(){
        $sec_id = I('sec_id');
        $section_info = $this->video->getVideoInfoBySectionId($sec_id);
        $result['aaData'] = $section_info;
        echo json_encode($result);
    }
    public function uploadVideo(){
        $config = array(
            'maxSize'    =>    0,
            'rootPath'   =>    VIDEO_PATH,
            'exts'       =>    array('mp4', 'wav','mov'),
            'autoSub'    =>    false,
        );
        $upload = new \Think\Upload($config);
        $upload->saveName = 'get_uuid';
        // 上传文件
        $info = $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功
            $filename = $info['add_upload_file']['name'];
            $uuid = $info['add_upload_file']['savename'];
            $result['state'] = true;
            $result['info']['filename'] = $filename;
            $result['info']['uuid'] = $uuid;
            echo json_encode($result);
        }
    }
    public function add_video(){
        $data = I();
        $sec_id = $data['sec_boss_add'];
        $con['sec_id'] = $sec_id;
        if (!$this->video_dao->create($data)){

            $result['state'] = false;
            $result['info'] = $this->video_dao->getError();

        }else{

            $order = $this->video->getMaxOrderBySecId($sec_id);
            $this->video_dao->order = $order+1;
            $info = $this->video_dao -> add();
            if ($info){
                $result['state'] = true;
                $result['info'] = '新增成功';
            }else{
                $result['state'] = false;
                $result['info'] = $this->video_dao->getError();
            }
        }
        echo json_encode($result);
    }
    public function edit_video(){
        $data = I();
        $result = $this->event->edit_data($this->video_dao,$data);
        echo json_encode($result);
    }
    public function changeUploadVideo(){
        $config = array(
            'maxSize'    =>    0,
            'rootPath'   =>    VIDEO_PATH,
            'exts'       =>    array('mp4', 'wav','mov'),
            'autoSub'    =>    false,
        );
        $upload = new \Think\Upload($config);
        $upload->saveName = 'get_uuid';
        // 上传文件
        $info = $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功
            $filename = $info['change_upload_file']['name'];
            $uuid = $info['change_upload_file']['savename'];
            $result['state'] = true;
            $result['info']['filename'] = $filename;
            $result['info']['uuid'] = $uuid;
            echo json_encode($result);
        }
    }
    public function change_video(){
        $data = I();
        $this->event->deleteVideo($data['change_vid_id']);
        $result = $this->event->edit_data($this->video_dao,$data);
        echo json_encode($result);
    }
    /* <-------------     学习资料管理   -------------> */
    public function  method_study_manage(){
        $this->display();
    }
}